package example.controller.validation;

import com.alibaba.fastjson.JSON;
import example.config.BusinessException;
import example.vo.ResponseEntity;
import example.vo.ValidationVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author guoQ.z
 * @date 2020/12/15 16:26
 * TODO
 */
@RestController
@RequestMapping("/validation")
public class Controller {

    @GetMapping("/testGet")
    public ResponseEntity testGet(@Valid ValidationVo validationVo) {
        if (StringUtils.isBlank(validationVo.getGender())) {
            throw new BusinessException("gender is null");
        }
        return ResponseEntity.success(JSON.toJSONString(validationVo));
    }

    @PostMapping("/testPost")
    public ResponseEntity testPost(@Valid @RequestBody ValidationVo validationVo) {
        return ResponseEntity.success(JSON.toJSONString(validationVo));
    }
}
